#ifndef __M25P16_H_
#define __M25P16_H_

void M_Spi_Write(unsigned char data);
unsigned char M_Spi_Read(void);
void M_Wren(void);
void M_Wrdi(void);
void M_Rdid(unsigned char *id);
unsigned char M_Rdsr(void);
void M_Wrsr(unsigned char status);
void M_Read(unsigned long int address,int number,unsigned char *data);
void M_Page_Program(unsigned long int address,int number,unsigned char *data);
void M_Sector_Erase(unsigned long int address);
void M_Bulk_Erase(void);
void M_Wait_Busy(void);
void M_Program(unsigned char data);

/*******  Instruction  ********/
#define M_i_write_enable  0x06
#define M_i_write_disable 0x04
#define M_i_read_id       0x9f
#define M_i_read_status   0x05
#define M_i_write_status  0x01
#define M_i_read_data     0x03
#define M_i_page_program  0x02
#define M_i_sector_erase  0xd8
#define M_i_bulk_erase    0xc7

#define M_Status_Wip	0x01
#define M_Status_Wel	0x02
#define M_Status_Bp0	0x04
#define M_Status_Bp1	0x08
#define M_Status_Bp2	0x10
#define M_Status_Srwd	0x80


#define M_SET_SDO()  GPIO_WriteHigh(GPIOA,GPIO_PIN_2)
#define M_CLR_SDO()  GPIO_WriteLow(GPIOA,GPIO_PIN_2)
#define M_SET_SCK()  GPIO_WriteHigh(GPIOD,GPIO_PIN_3)
#define M_CLR_SCK()  GPIO_WriteLow(GPIOD,GPIO_PIN_3)
#define M_SET_CS()   GPIO_WriteHigh(GPIOD,GPIO_PIN_2)
#define M_CLR_CS()   GPIO_WriteLow(GPIOD,GPIO_PIN_2)
#define M_GET_SDI()  GPIO_ReadInputPin(GPIOA,GPIO_PIN_1)



#endif /* end __M25P16_H_ */